<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>函数参数默认值的位置</title>
  </head>
  <body>
    <p>通常，带默认值的参数应该在最后，因为只有这样这个参数可以省略</p>
    <pre>
      function f(x=1,y){
        console.log([x, y]);
      }
      f();
      f(2)
      f(,1)  //报错  Uncaught SyntaxError: Unexpected token ','
      f(undefined,1)
    </pre>
  </body>
</html>
<script>
  function f(x = 1, y) {
    console.log([x, y]);
  }
  f();
  f(2);
  //f(,1)      //报错 Uncaught SyntaxError: Unexpected token ','
  f(undefined, 1);
</script>
